﻿@model cloudscribe.Core.Web.ViewModels.SiteSettings.SiteListViewModel
@using cloudscribe.Web.Pagination
@addTagHelper "*, cloudscribe.Web.Pagination"
@using cloudscribe.Core.Web
@using cloudscribe.Core.Models
@using cloudscribe.Web.Navigation
@using Microsoft.Extensions.Options
@using Microsoft.Extensions.Localization
@inject IStringLocalizer<CloudscribeCore> sr
@inject IOptions<MultiTenantOptions> multiTenantOptions
@{
    var FolderHostLabel = sr["Preferred Host Name"];
    var options = multiTenantOptions.Value;
    if (options.Mode == MultiTenantMode.FolderName)
    {
        FolderHostLabel = sr["Folder"];
    }
    
}
<div class="row">
    <div class="col-md-10 col-md-push-2">
        <h2>@ViewData["Title"]</h2>
        <table class="table table-striped table-bordered">
            <tr>
                <th>
                    <a class="btn btn-xs btn-default" asp-action="NewSite"
                       asp-controller="SiteAdmin"
                       asp-route-slp="@Model.Sites.PageNumber">@sr["New Site"]</a>
                </th>
                <th>
                    @sr["Site Name"]
                </th>
                <th>
                    @FolderHostLabel
                </th>
            </tr>
            @foreach (var item in Model.Sites.Data)
            {
                <tr class="@(item.IsServerAdminSite ? "adminsite danger" : "childsite")">
                    <td>
                        <a class="btn btn-xs btn-default" asp-action="SiteInfo"
                           asp-controller="SiteAdmin"
                           asp-route-siteid="@item.Id"
                           asp-route-slp="@Model.Sites.PageNumber">@sr["Settings"]</a>

                        @if (!(options.Mode == MultiTenantMode.FolderName))
                        {
                            <a class="btn btn-xs btn-default hostmap" asp-action="SiteHostMappings"
                               asp-controller="SiteAdmin"
                               asp-route-siteid="@item.Id"
                               asp-route-slp="@Model.Sites.PageNumber">@sr["Domain Mappings"]</a>
                        }
                    </td>
                    <td>
                        @Html.DisplayFor(modelItem => item.SiteName) @sr["Id:"] @item.Id
                        @sr["AliasId:"] @item.AliasId
                    </td>
                    <td>
                        @if (options.Mode == MultiTenantMode.FolderName)
                        {
                            <a href="/@item.SiteFolderName" target="_blank">/@item.SiteFolderName</a>
                        }
                        else
                        {
                            if (!string.IsNullOrWhiteSpace(item.PreferredHostName))
                            {
                                <a href="http://@item.PreferredHostName" target="_blank">@item.PreferredHostName</a>
                            }
                        }
                    </td>
                </tr>
            }
        </table>
        <div>
            <cs-pager 
                      asp-action="SiteList" asp-controller="SiteAdmin"
                      asp-route-pagesize="@Model.Sites.PageSize"
                      cs-paging-pagesize="@Model.Sites.PageSize"
                      cs-paging-pagenumber="@Model.Sites.PageNumber"
                      cs-paging-totalitems="@Model.Sites.TotalItems"
                      cs-first-page-title='@sr["First Page"]'
                      cs-last-page-title='@sr["Last Page"]'
                      cs-previous-page-title='@sr["Previous page"]'
                      cs-next-page-title='@sr["Next page"]'></cs-pager>
        </div>
    </div>
    <div class="col-md-2 col-md-pull-10 hidden-xs hidden-sm">
        @await Component.InvokeAsync("Navigation", new { viewName = "SideNavAlt1", filterName = NamedNavigationFilters.ParentTree, startingNodeKey = "SiteAdmin" })
    </div>
</div>
@section scripts {
    @{ await Html.RenderPartialAsync("_SideMenuScriptsPartial"); }
}
